<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="80px"
    >
      <el-form-item label="店铺id" prop="shopId">
        <el-input
          v-model="queryParams.shopId"
          placeholder="请输入店铺id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="店铺名称" prop="shopName">
        <el-input
          v-model="queryParams.shopName"
          placeholder="请输入店铺名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="spu" prop="spu">
        <el-input
          v-model="queryParams.spu"
          placeholder="请输入spu"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="skc" prop="skc">
        <el-input
          v-model="queryParams.skc"
          placeholder="请输入skc"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="sku" prop="sku">
        <el-input
          v-model="queryParams.sku"
          placeholder="请输入sku"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
        <el-button
          :icon="!isOpen ? 'el-icon-arrow-down' : 'el-icon-arrow-up'"
          size="mini"
          @click="shouqi"
          >展开/收起</el-button
        >
      </el-form-item>
      <div v-if="isOpen">
        <el-form-item label="数量" prop="inventoryAmount">
          <el-input
            v-model="queryParams.inventoryAmount"
            placeholder="请输入数量"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="是否上架" prop="isShelf">
          <el-input
            v-model="queryParams.isShelf"
            placeholder="请输入是否上架"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="仓库编码" prop="warehouseCode">
          <el-input
            v-model="queryParams.warehouseCode"
            placeholder="请输入仓库编码"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="仓库名称" prop="warehouseName">
          <el-input
            v-model="queryParams.warehouseName"
            placeholder="请输入仓库名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="颜色" prop="colorProperty">
          <el-input
            v-model="queryParams.colorProperty"
            placeholder="请输入颜色"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="货号" prop="productNo">
          <el-input
            v-model="queryParams.productNo"
            placeholder="请输入货号"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="一级" prop="firstLevelColumn">
          <el-input
            v-model="queryParams.firstLevelColumn"
            placeholder="请输入一级"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="三级" prop="secondLevelColumn">
          <el-input
            v-model="queryParams.secondLevelColumn"
            placeholder="请输入三级"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="产品/配件" prop="productAccessory">
          <el-input
            v-model="queryParams.productAccessory"
            placeholder="请输入产品/配件"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="商品季节" prop="productSeason">
          <el-input
            v-model="queryParams.productSeason"
            placeholder="请输入商品季节"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="渠道" prop="channel">
          <el-input
            v-model="queryParams.channel"
            placeholder="请输入渠道"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="品牌" prop="brand">
          <el-input
            v-model="queryParams.brand"
            placeholder="请输入品牌"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="成本" prop="cost">
          <el-input
            v-model="queryParams.cost"
            placeholder="请输入成本"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="上架时间" prop="newTime">
          <el-date-picker
            clearable
            v-model="queryParams.newTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择上架时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="尺寸" prop="size">
          <el-input
            v-model="queryParams.size"
            placeholder="请输入尺寸"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
      </div>
      <!-- <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item> -->
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5" style="display: none">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['product:BiTi1DailySnapshot:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5" style="display: none">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['product:BiTi1DailySnapshot:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5" style="display: none">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['product:BiTi1DailySnapshot:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['product:BiTi1DailySnapshot:export']"
          >导出</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-refresh"
          size="mini"
          @click="handleRefreshCache"
          >同步数据</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="BiTi1DailySnapshotList"
      @selection-change="handleSelectionChange"
    >
      <!-- <el-table-column
          width="140" type="selection" width="55" align="center" /> -->
      <el-table-column
        width="140"
        label="sku库存表id"
        align="center"
        prop="id"
      />
      <el-table-column
        width="140"
        label="店铺id"
        align="center"
        prop="shopId"
      />
      <el-table-column
        width="140"
        label="店铺名称"
        align="center"
        prop="shopName"
      />
      <el-table-column width="140" label="item" align="center" prop="item" />
      <el-table-column width="140" label="spu" align="center" prop="spu" />
      <el-table-column width="140" label="skc" align="center" prop="skc" />
      <el-table-column width="140" label="sku" align="center" prop="sku" />
      <el-table-column
        width="140"
        label="订单占用库存"
        align="center"
        prop="inventoryReserved"
      />
      <el-table-column label="实际库存" align="center" prop="inventoryActual" />
      <el-table-column
        width="140"
        label="数量"
        align="center"
        prop="inventoryAmount"
      />
      <el-table-column
        width="140"
        label="是否上架"
        align="center"
        prop="isShelf"
      />
      <el-table-column
        width="140"
        label="仓库编码"
        align="center"
        prop="warehouseCode"
      />
      <el-table-column
        width="140"
        label="仓库名称"
        align="center"
        prop="warehouseName"
      />

      <el-table-column
        width="140"
        label="颜色"
        align="center"
        prop="colorProperty"
      />
      <el-table-column width="140" label="尺码" align="center" prop="size" />
      <el-table-column
        width="140"
        label="一级"
        align="center"
        prop="firstLevelColumn"
      />
      <el-table-column
        width="140"
        label="二级"
        align="center"
        prop="firstLevelExtendedColumn"
      />
      <el-table-column
        width="140"
        label="三级"
        align="center"
        prop="secondLevelColumn"
      />
      <el-table-column
        width="140"
        label="产品/配件"
        align="center"
        prop="productAccessory"
      />
      <el-table-column
        width="140"
        label="商品季节"
        align="center"
        prop="productSeason"
      />
      <el-table-column width="140" label="渠道" align="center" prop="channel" />
      <el-table-column width="140" label="品牌" align="center" prop="brand" />
      <el-table-column width="140" label="成本" align="center" prop="cost" />
      <el-table-column
        width="140"
        label="上架时间"
        align="center"
        prop="newTime"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.newTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column width="140" label="尺寸" align="center" prop="size" />
      <el-table-column
        width="140"
        label="仓库类型"
        align="center"
        prop="warehouseType"
      />
      <!-- <el-table-column
        width="140"
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['product:BiTi1DailySnapshot:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['product:BiTi1DailySnapshot:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column> -->
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改TI1日快照对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="店铺id" prop="shopId">
          <el-input v-model="form.shopId" placeholder="请输入店铺id" />
        </el-form-item>
        <el-form-item label="店铺名称" prop="shopName">
          <el-input v-model="form.shopName" placeholder="请输入店铺名称" />
        </el-form-item>
        <el-form-item label="spu" prop="spu">
          <el-input v-model="form.spu" placeholder="请输入spu" />
        </el-form-item>
        <el-form-item label="skc" prop="skc">
          <el-input v-model="form.skc" placeholder="请输入skc" />
        </el-form-item>
        <el-form-item label="sku" prop="sku">
          <el-input v-model="form.sku" placeholder="请输入sku" />
        </el-form-item>
        <el-form-item label="数量" prop="inventoryAmount">
          <el-input v-model="form.inventoryAmount" placeholder="请输入数量" />
        </el-form-item>
        <el-form-item label="是否上架" prop="isShelf">
          <el-input v-model="form.isShelf" placeholder="请输入是否上架" />
        </el-form-item>
        <el-form-item label="仓库编码" prop="warehouseCode">
          <el-input v-model="form.warehouseCode" placeholder="请输入仓库编码" />
        </el-form-item>
        <el-form-item label="仓库名称" prop="warehouseName">
          <el-input v-model="form.warehouseName" placeholder="请输入仓库名称" />
        </el-form-item>
        <el-form-item label="颜色" prop="colorProperty">
          <el-input v-model="form.colorProperty" placeholder="请输入颜色" />
        </el-form-item>
        <el-form-item label="货号" prop="productNo">
          <el-input v-model="form.productNo" placeholder="请输入货号" />
        </el-form-item>
        <el-form-item label="一级" prop="firstLevelColumn">
          <el-input v-model="form.firstLevelColumn" placeholder="请输入一级" />
        </el-form-item>
        <el-form-item label="三级" prop="secondLevelColumn">
          <el-input v-model="form.secondLevelColumn" placeholder="请输入三级" />
        </el-form-item>
        <el-form-item label="产品/配件" prop="productAccessory">
          <el-input
            v-model="form.productAccessory"
            placeholder="请输入产品/配件"
          />
        </el-form-item>
        <el-form-item label="商品季节" prop="productSeason">
          <el-input v-model="form.productSeason" placeholder="请输入商品季节" />
        </el-form-item>
        <el-form-item label="渠道" prop="channel">
          <el-input v-model="form.channel" placeholder="请输入渠道" />
        </el-form-item>
        <el-form-item label="品牌" prop="brand">
          <el-input v-model="form.brand" placeholder="请输入品牌" />
        </el-form-item>
        <el-form-item label="成本" prop="cost">
          <el-input v-model="form.cost" placeholder="请输入成本" />
        </el-form-item>
        <el-form-item label="上架时间" prop="newTime">
          <el-date-picker
            clearable
            v-model="form.newTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择上架时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="尺寸" prop="size">
          <el-input v-model="form.size" placeholder="请输入尺寸" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listBiTi1DailySnapshot,
  getBiTi1DailySnapshot,
  delBiTi1DailySnapshot,
  addBiTi1DailySnapshot,
  updateBiTi1DailySnapshot,
  dailySnapSynchroData,
} from "@/api/chart/BiTi1DailySnapshot";

export default {
  name: "BiTi1DailySnapshot",
  data() {
    return {
      isOpen: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // TI1日快照表格数据
      BiTi1DailySnapshotList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        shopId: null,
        shopName: null,
        spu: null,
        skc: null,
        sku: null,
        inventoryAmount: null,
        isShelf: null,
        warehouseCode: null,
        warehouseName: null,
        colorProperty: null,
        productNo: null,
        firstLevelColumn: null,
        secondLevelColumn: null,
        productAccessory: null,
        productSeason: null,
        channel: null,
        brand: null,
        cost: null,
        newTime: null,
        size: null,
        warehouseType: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        shopName: [
          { required: true, message: "店铺名称不能为空", trigger: "blur" },
        ],
        spu: [{ required: true, message: "spu不能为空", trigger: "blur" }],
        skc: [{ required: true, message: "skc不能为空", trigger: "blur" }],
        sku: [{ required: true, message: "sku不能为空", trigger: "blur" }],
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 刷新缓存按钮操作 Warning*/
    handleRefreshCache() {
      this.$modal.msgWarning("数据正在同步，请稍候");
      // const obj = { updateDate: this.timeGap.startTime };
      dailySnapSynchroData().then(() => {
        this.$modal.msgSuccess("同步数据成功");
        this.getList();
        // this.$store.dispatch('dict/cleanDict');
      });
    },
    //搜索栏展示与收起
    shouqi() {
      // console.log(1);
      this.isOpen = !this.isOpen;
    },
    /** 查询TI1日快照列表 */
    getList() {
      this.loading = true;
      listBiTi1DailySnapshot(this.queryParams).then((response) => {
        this.BiTi1DailySnapshotList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        shopId: null,
        shopName: null,
        spu: null,
        skc: null,
        sku: null,
        inventoryAmount: null,
        isShelf: null,
        warehouseCode: null,
        warehouseName: null,
        colorProperty: null,
        productNo: null,
        firstLevelColumn: null,
        secondLevelColumn: null,
        productAccessory: null,
        productSeason: null,
        channel: null,
        brand: null,
        cost: null,
        newTime: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        size: null,
        warehouseType: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加TI1日快照";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getBiTi1DailySnapshot(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改TI1日快照";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateBiTi1DailySnapshot(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addBiTi1DailySnapshot(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除TI1日快照编号为"' + ids + '"的数据项？')
        .then(function () {
          return delBiTi1DailySnapshot(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "product/BiTi1DailySnapshot/export",
        {
          ...this.queryParams,
        },
        `BiTi1DailySnapshot_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
